package com.sl.au.repository;

import com.sl.au.entity.Device;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true)
public interface DeviceRepository extends JpaRepository<Device, String> {
	/// 获得单泵的信息
	@Query(" select s from Device s where s.deviceModel like '%'+?1+'%' "
			+ "or s.deviceType like '%'+?1+'%' "
			+ "or s.deviceName like '%'+?1+'%' "
			+ "or s.mainMaterial like '%'+?1+'%' "
			+ "or s.machine like '%'+?1+'%'")
	Page<Device> getSinglePump(String key, Pageable pageable);
	
	@Query(" select count(s) from Device s where s.deviceModel like '%'+?1+'%' "
			+ "or s.deviceType like '%'+?1+'%' "
			+ "or s.deviceName like '%'+?1+'%' "
			+ "or s.mainMaterial like '%'+?1+'%' "
			+ "or s.machine like '%'+?1+'%'")
	long getCount(String key);

	@Query(" select s from Device s where s.deviceModel=?1 ")
	List<Device> findByDeviceModel(String deviceModel);
	
	//利用设备型号验证是否记录>1
	@Query(" select count(s) from Device s where s.deviceType=?1")
	long getReCount(String deviceType);
	//根据设备型号找到记录
	List<Device>findByDeviceType(String deviceType);
}